package com.yc.damai.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.damai.biz.IDmPromotionService;
import com.yc.damai.dto.Result;
import com.yc.damai.entity.DmPromotion;
import com.yc.damai.mapper.DmPromotionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ly
 * @since 2024-09-28
 */
@RestController
@RequestMapping("dmPromotion")
public class DmPromotionController {

    @Autowired
    DmPromotionMapper promotionMapper;
    @Autowired
    IDmPromotionService promotionService;

    @RequestMapping("getNoBegin")
    DmPromotion getNoBegin(){
        DmPromotion ret = promotionMapper.selectNoBegin();
//        LambdaQueryWrapper<DmPromotion> lqw = new LambdaQueryWrapper<>();
//        lqw.eq(DmPromotion::getStatus, 0);
//        lqw.orderByAsc(DmPromotion::getBegin);
//        Page<DmPromotion> page = new Page<>(1,1);
//        page = promotionMapper.selectPage(page, lqw);
//        if(page.getRecords().isEmpty()){
//            return null;
//        }
        return ret;
    }

    @RequestMapping("begin")
    Result begin(int pmid){
        promotionService.begin(pmid);
        return new Result(1, "大促活动开始了!", null);
    }

    @RequestMapping("end")
    Result end(@RequestBody DmPromotion dmPromotion){
        promotionService.end(dmPromotion);
        return new Result(1, "大促活动结束了!", null);
    }

}
